package chapter4;
import java.util.Scanner;
/****************************************************************
 * Author：icynlau
 * Description: 判断输入是否符合社保号码的格式
 * Date:2021/4/2
 * ***************************************************************
 */
public class exc4_21 {
	public static void main(String[] args) {
		Scanner input=new Scanner(System.in);
		System.out.print("Enter a SSN: ");
		String s=input.next();
		if(s.length()!=11) {
			System.out.println(s+" is an invalid social security number.");
			System.exit(1);
		}else {
			int k=0; //as an index
			for(int i=0;i<3;i++) {
				if(!(s.charAt(k)>='0'&&s.charAt(k)<='9')) {
					System.out.println(s+" is an invalid social security number.");
					System.exit(1);
				}else {
					k++;
				}
			}
			
			if(!(s.charAt(k)=='-')) {
				System.out.println(s+" is an invalid social security number.");
				System.exit(1);
			}
			k++;
			
			for(int i=0;i<2;i++) {
				if(!(s.charAt(k)>='0'&&s.charAt(k)<='9')) {
					System.out.println(s+" is an invalid social security number.");
					System.exit(1);
				}else {
					k++;
				}
			}
			
			if(!(s.charAt(k)=='-')) {
				System.out.println(s+" is an invalid social security number.");
				System.exit(1);
			}
			k++;
			
			for(int i=0;i<4;i++) {
				if(!(s.charAt(k)>='0'&&s.charAt(k)<='9')) {
					System.out.println(s+" is an invalid social security number.");
					System.exit(1);
				}else {
					k++;
				}
			}
			
			System.out.println(s+" is a valid social security number.");
			
			
		}
		
	}

}
